package com.jincp.common.http.okhttp;


import com.jincp.common.http.IHttpCallback;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by lidongyang on 2016/5/11.
 */
public class ProgressRequestInterceptor implements Interceptor {

    private IHttpCallback callback;

    public ProgressRequestInterceptor(IHttpCallback callback) {
        this.callback = callback;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request original = chain.request();
        Request request = original.newBuilder()
                .method(original.method(), new ProgressRequestBody(original.body(), callback))
                .build();
        return chain.proceed(request);
    }
}
